#-------------------------------------------------------------------
# Project Invasion of the aliens 
# name game.py
# purpose main game loop
#
# authors Chris L'Heureux, Tyler Plante, Jackson Morse
# main author Chris L'Heureux
#
# created 12/3/12
# Copyright (C) Chris L'Heureux
# License New BSD\
#------------------------------------------------------------------  

import pygame, math

class Block(pygame.sprite.Sprite):
    def __init__(self, blockSize, position, screenSize):
        pygame.sprite.Sprite.__init__(self, self.containers)
        print position
        self.blockSize = blockSize
        self.images = []
        self.images += [pygame.image.load("Game Image/StoneBlock.png")]
        newImages = []
        for image in self.images:
            print self.blockSize
            newImages += [pygame.transform.scale(image, [self.blockSize, self.blockSize])]
        self.images = newImages
        self.frame = 0
        self.maxFrame = len(self.images)-1
        self.image = self.images[self.frame]
        self.rect = self.image.get_rect()
        
        self.place(position)
        self.radius = self.rect.width/2
        self.living = True
        self.didHit = False
        self.screenSize = self.screenWidth, self.screenHeight = screenSize

    def __str__(self):
        return "I am a wall" + str(self.rect.center)
        
        
    def place(self, position):
        self.rect.center = position
        #print "I've moved to", position    
    
    def distToPoint(self, pt):
        x1 = self.rect.center[0]
        x2 = pt[0]
        y1 = self.rect.center[1]
        y2 = pt[1]
        return math.sqrt(((x2-x1)**2)+((y2-y1)**2))

    def collide(self, other):
        if (self.rect.right > other.rect.left 
            and self.rect.left < other.rect.right):
            if (self.rect.bottom > other.rect.top and 
                self.rect.top < other.rect.bottom):
                if (self.distToPoint(other.rect.center)
                    < self.radius + other.radius):
                    print "potato"
